﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
///SqlHelp 的摘要说明
/// </summary>
public class SqlHelp
{
    private static string connStr = System.Configuration.ConfigurationManager.AppSettings["connStr"];
    public static DataSet GetDataSet(string sql, SqlParameter[] paras)
    {
        DataSet ds=new DataSet();
        SqlDataAdapter sqlDA = new SqlDataAdapter(sql, connStr);
        try
        {
            if (paras != null)
            {
                sqlDA.SelectCommand.Parameters.AddRange(paras);
            }
            sqlDA.Fill(ds);
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return ds;  
    }

    public static void Excute(string sql, SqlParameter[] paras)
    {
        DataSet ds = new DataSet();
        SqlConnection sqlConn = new SqlConnection(connStr);
        SqlCommand cmd = new SqlCommand(sql, sqlConn);
        try
        {
            if (paras != null)
            {
                cmd.Parameters.AddRange(paras);
            }
            if (sqlConn.State == ConnectionState.Closed)
                sqlConn.Open();
            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

}